package com.you.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.you.shortlink.project.dao.entity.ShortLinkDO;
import com.you.shortlink.project.dto.req.ShortLinkPageReqDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 短链接持久层
 */
public interface ShortLinkMapper extends BaseMapper<ShortLinkDO> {

    /**
     * 更新短链接统计信息
     */
    @Update("""
            UPDATE t_link SET total_pv = total_pv + #{totalPv}, total_uv = total_uv + #{totalUv}, total_uip = total_uip + #{totalUip}
            WHERE full_short_url = #{fullShortUrl} AND gid = #{gid};
            """)
    void increaseStats(@Param("fullShortUrl") String fullShortUrl,
                       @Param("gid") String gid,
                       @Param("totalPv") Integer totalPv,
                       @Param("totalUv") Integer totalUv,
                       @Param("totalUip") Integer totalUip
    );

    /**
     * 分页查询短链接监控排序数据
     */
    IPage<ShortLinkDO> pageLink(ShortLinkPageReqDTO requestParam);

}
